package com.traveldream.entities;

import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;


/**
 * The persistent class for the invite database table.
 * 
 */
@Entity
@NamedQueries({
	@NamedQuery(name="Invite.findAll", query="SELECT i FROM Invite i"),
	@NamedQuery(name="Invite.findBySender",query="SELECT i FROM Invite i WHERE i.id.customerBookedEmail LIKE :senderEmail"),
	@NamedQuery(name="Invite.findByReceiver",query="SELECT i FROM Invite i WHERE i.receivingEmail LIKE :receiverEmail")
})

public class Invite implements Serializable {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private InvitePK id;

	@Temporal(TemporalType.DATE)
	private Date date;

	@Column(name="receiving_email")
	private String receivingEmail;

	//bi-directional many-to-one association to Booking
	@ManyToOne
	@JoinColumns({
		@JoinColumn(name="booked_packet_id", referencedColumnName="packet_id"),
		@JoinColumn(name="customer_booked_email", referencedColumnName="customer_email")
		})
	private Booking booking;

	public Invite() {
	}

	public InvitePK getId() {
		return this.id;
	}

	public void setId(InvitePK id) {
		this.id = id;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getReceivingEmail() {
		return this.receivingEmail;
	}

	public void setReceivingEmail(String receivingEmail) {
		this.receivingEmail = receivingEmail;
	}

	public Booking getBooking() {
		return this.booking;
	}

	public void setBooking(Booking booking) {
		this.booking = booking;
	}
	
	@Override
	public boolean equals(Object o) {
		Invite i=(Invite)o;
		return this.booking.equals(i.booking) && this.receivingEmail.equals(receivingEmail);		
	}
	
	//not implemented
	public void sendEmail(){
		// this method is left unimplemented because of 
		// additional configuration required on GlassFish 
		// for a JavaMailSession
		
		// the aim of this method is to send an email to invite receiver with suggested package summary
		// the receiver so can register to the webapp and accept his invite
		
	}

}